<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$basic=$this->setting;
$return['basic']=$basic;
$return['banner']=$basic['hdps'];
$this->session('type',$_RQ['type']);
if($_RQ['type']){
	$this->session('type',$_RQ['type']);
}
if($_RQ['op']=='main'){
	
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_sitenews/index/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['params']=array('group_id'=>0,'keyword'=>'','ishot'=>1,'isall'=>1);
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$params=array('ishelp'=>0,'uniacid'=>$_SESSION['uniacid']);
	if($this->setting['is_one']){
		$params['plugin_name']='jy_sitenews';
	}
	$return['groups']=pdo_getall('core_account_article_fenlei',$params,'','','paixu desc');
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	set_html('title',$basic['title']?$basic['title']:'新闻中心');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('ishelp'=>0,'uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['title']=$_RQ['keyword'];
	}
	$fenleiid=intval($_RQ['group_id']);
	if($fenleiid){
		$params['fenlei']=$fenleiid;
	}
	$return['params']['group_id']=$fenleiid;
	if($this->setting['is_one']){
		$params['plugin_name']='jy_sitenews';
	}
	$fields=array('id','title','content','fenlei','keyword','createtime','readnum','re_readnum','likenum','status','desc','pic_url','yingxiao');
	$orderby=array();
	$_RQ['page'] = $_RQ['page'] ? $_RQ['page'] : 1;
	$pindex = max(1, intval($_RQ['page']));
	if(intval($_RQ['num'])){
		$psize = intval($_RQ['num']);
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('core_account_article',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['desc2'] = strip_tags(str_replace('&nbsp;','',$item['content']));
			$item['desc'] = $item['desc'] ? $item['desc'] : cfc('tools')->substr($item['desc2'],0,36);
			$item['picurl'] = $item['pic_url'] ? $item['pic_url'] : '../core/resource/images/nopic.jpg';
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['fenlei']=$fenlei[$item['fenlei']]['title'];
			$item['url']=custom_url('jy_sitenews/list/detail/id='.$item['id'],true);
			$item['readnum'] = $item['readnum']+$item['re_readnum'];
			$item['likes']=pdo_count('core_account_article_like',array('article_id'=>$item['id'],'like'=>1,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	exi($return);
}